package com.dengbw.systemtransfer.model;

import lombok.AllArgsConstructor;
import lombok.Getter;
import lombok.Setter;
import lombok.ToString;
import org.springframework.util.CollectionUtils;

import java.util.ArrayList;
import java.util.List;
import java.util.stream.Collectors;

/**
 * @author dengbw
 * @date 2021/8/9 2:24 下午
 */
@Getter
@Setter
@AllArgsConstructor
@ToString
public class DepInfo {
    private Long xiangzhen;
    private Long fuwu;
    private List<CunDepInfo> cunDepInfoList;

    public DepInfo() {
        cunDepInfoList = new ArrayList<>();
    }

    public List<Long> subIds() {
        List<Long> ids = new ArrayList<>(cunDepInfoList.size() + 2);
        ids.addAll(cunIds());
        ids.addAll(otherIds());
        return ids;
    }

    public List<Long> cunIds() {
        List<Long> ids = new ArrayList<>(cunDepInfoList.size());
        if (!CollectionUtils.isEmpty(cunDepInfoList)) {
            ids.addAll(cunDepInfoList.stream().map(CunDepInfo::getCunDepId).collect(Collectors.toList()));
        }
        return ids;
    }

    public List<Long> otherIds() {
        List<Long> ids = new ArrayList<>(2);
        if (xiangzhen != null) {
            ids.add(xiangzhen);
        }
        if (fuwu != null) {
            ids.add(fuwu);
        }
        return ids;
    }
}
